<template>
  <div class="content-grid">
    <div 
      v-for="item in contentData" 
      :key="item.id"
      class="content-card"
    >
      <!-- 图片类型内容 -->
      <div v-if="item.type === 'image'" class="card-image">
        <img :src="item.image" :alt="item.title" />
      </div>
      
      <!-- 文本类型内容 -->
      <div v-else-if="item.type === 'text'" class="card-text">
        <div class="text-content">
          <h3>{{ item.title }}</h3>
          <p>{{ item.content }}</p>
        </div>
      </div>
      
      <!-- 卡片底部信息 -->
      <div class="card-footer">
        <div class="author-info">
          <img :src="item.avatar" :alt="item.author" class="author-avatar" />
          <span class="author-name">{{ item.author }}</span>
        </div>
        
        <div class="card-actions">
          <button class="action-btn like-btn" @click="toggleLike(item)">
            <img src="/src/assets/icons/like.png" alt="点赞" class="action-icon" />
            <span>{{ formatLikes(item.likes) }}</span>
          </button>
        </div>
      </div>
      
    </div>
  </div>
</template>

<script setup>
import { defineProps } from 'vue'

const props = defineProps({
  contentData: {
    type: Array,
    required: true
  }
})

const formatLikes = (likes) => {
  if (likes >= 10000) {
    return (likes / 10000).toFixed(1) + 'w'
  }
  return likes.toString()
}

const toggleLike = (item) => {
  // 这里可以添加点赞逻辑
  console.log('点赞:', item.title)
}
</script>

<style scoped>
.content-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  padding: 20px 30px 20px 20px;
  width: 100%;
  box-sizing: border-box;
}

.content-card {
  background: transparent;
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
  transition: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.content-card:hover {
  transform: none;
  box-shadow: none;
}

.card-image {
  position: relative;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 8px;
}

.card-image img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}


.card-text {
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
  margin-bottom: 8px;
}

.text-content h3 {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  margin-bottom: 8px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.text-content p {
  font-size: 14px;
  color: #666;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  padding: 8px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.author-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.author-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.author-name {
  font-size: 13px;
  color: #333;
  font-weight: 500;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: #666;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  transition: all 0.2s;
}

.action-icon {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.action-btn:hover {
  background: #f5f5f5;
  color: #333;
}

.like-btn:hover {
  color: #ff2442;
}


/* 响应式设计 */
@media (max-width: 1200px) {
  .content-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 900px) {
  .content-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 600px) {
  .content-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 400px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
}
</style>
